package mirrormonkey.util.netevent.queue;

import java.util.Deque;
import java.util.LinkedList;

import mirrormonkey.util.netevent.NetworkEvent;

/**
 * The most basic <tt>EventQueue</tt>. Incoming events are stored in a simple
 * queue. In every frame, every event that was received since the last frame
 * will be processed and consumed.
 * 
 * @author Philipp Christian Loewner
 * 
 */
public class SimpleEventQueue implements EventQueue {

	/**
	 * all inbound events since the last frame
	 */
	private final Deque<NetworkEvent> events = new LinkedList<NetworkEvent>();

	@Override
	public void add(NetworkEvent event) {
		events.add(event);
	}

	@Override
	public int getSize() {
		return events.size();
	}

	@Override
	public void processEvents() {
		while (!events.isEmpty()) {
			events.pollFirst().process();
		}
	}

}
